package cn.the.angry.anim;

import java.awt.Image;
import java.awt.image.BufferedImage;

import org.jbox2d.common.*;
import org.jbox2d.dynamics.Body;

import cn.the.angry.tests.TestUtils;

public class PhysicalObject
{
	private final AbstractObject object;
	private Body objectBody;
	private final float scale;
	
	public PhysicalObject(final AbstractObject object)
	{
		this(object, null, 1f);
	}
	
	public PhysicalObject(final AbstractObject object, final float scale)
	{
		this(object, null, scale);
	}
			
	public PhysicalObject(final AbstractObject object, final Body body, final float scale)
	{
		this.object = object;
		this.objectBody=body;
		this.scale=scale;
	}

	public Body getObjectBody()
	{
		return objectBody;
	}
	public void setObjectBody(final Body objectBody)
	{
		this.objectBody = objectBody;
	}
	
	public Vec2 getLocation()
	{
		return objectBody.getMemberPosition();
	}
	
	public int getAngle()
	{
		return (int) (objectBody.getAngle()*100);
	}

	public Image getImage()
	{
		if(getAngle()==0)
			return object.getImage();
		else
			return TestUtils.rotateImage((BufferedImage) object.getImage(), getFrameWidth(), getFrameHeight(), getAngle());
	}

	public int getFrameWidth()
	{
		return (int) (object.getFrameWidth()*scale);
	}

	public int getFrameHeight()
	{
		return (int) (object.getFrameHeight()*scale);
	}

	public void setState(boolean bool)
	{
		object.setState(bool);
	}

	public int getFramesCount()
	{
		return object.getFramesCount();
	}

	public void setLinearVelocity(Vec2 v)
	{
		objectBody.setLinearVelocity(v);
	}

	public Vec2 getLinearVelocity()
	{
		return objectBody.getLinearVelocity();
	}

	public void setData(Object key, Object value)
	{		
		object.setData(key, value);
	}

	public Object getData(Object key)
	{
		return object.getData(key);
	}
	
	
}
